#!/bin/sh
### BEGIN INIT INFO
# Provides:          lark
# Required-Start:    $remote_fs $network
# Required-Stop:     $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO

# Author: pingx <pingx@jumei.com>

PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="lark"
NAME=lark
USER=root
GROUP=root
DAEMON=/usr/bin/$NAME
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

. /etc/rc.d/init.d/functions

DAEMON_ARGS="start --server_agent_read_local_timeout=35s"

case "$1" in
  start)
    echo -n "Starting $DESC: "
    /usr/sbin/start-stop-daemon --start --pidfile $PIDFILE \
      --chuid $USER  --make-pidfile --background \
      --startas /bin/bash -- -c "exec $DAEMON $DAEMON_ARGS 1>>/home/logs/lark/lark.stdout.log 2>>/home/logs/lark/lark.stderr.log"
    if [ "$?" != 0 ] ; then
        echo " failed"
        exit 1
    fi
    echo "$NAME.......................ok"
    ;;
  stop)
    echo "Stopping $DESC: "
    /usr/sbin/start-stop-daemon --stop --pidfile $PIDFILE --verbose
    if [ "$?" != 0 ] ; then
       echo " failed"
       exit 1
    fi
    rm -f $PIDFILE
    echo "$NAME.......stop"
    ;;
  restart)
    echo "Restarting $DESC: "
    $0 stop && $0 start
    echo "$NAME."
    ;;
  status)
     ps -ef  | grep  '/usr/bin/lark start' |grep  -v grep  &>/dev/null
     if  [ "$?" == 0 ] ; then
            echo "lark is running..."
            exit 0
     else
            echo "lark is stop"
            exit 3
     fi
    ;;
  *)
    echo "Usage: /etc/init.d/$NAME {start|stop|restart|status}"
    exit 1
    ;;
esac

exit 0
